package com.pansoft.openplanet.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.efounder.chat.view.CommonOtherPopWindow;
import com.efounder.utils.ResStringUtil;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.activity.WalletAvatarAndNameSetupActivity;
import com.pansoft.openplanet.activity.WalletChangeActivity;
import com.pansoft.openplanet.activity.WalletTypeSelectActivity;
import com.pansoft.openplanet.bean.Account;
import com.pansoft.openplanet.constant.IPAssetsConstant;
import com.pansoft.openplanet.db.AccountDao;
import com.pansoft.openplanet.util.ChainParamsUtil;
import com.pansoft.openplanet.util.EosNetParamUtil;

import java.util.List;

public class StarAssetWalletPopup {

    /**
     * @param context   context
     * @param imageView 图标
     * @param chainId
     */
    public static void showPopup(final Context context, View imageView, final int chainId) {
        final CommonOtherPopWindow commonOtherPopWindow = new CommonOtherPopWindow((Activity) context);
        commonOtherPopWindow.addMenuButton(ResStringUtil.getString(R.string.open_planet_asset_etc_wallet_create), R.drawable.create_wallet)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //创建钱包
                        if (chainId == IPAssetsConstant.CHAIN_ID_EOS) {
                            WalletAvatarAndNameSetupActivity.start(context, WalletTypeSelectActivity.MODE_CREATE_NEW,
                                    EosNetParamUtil.getEosChainId());
                        } else {
                            WalletAvatarAndNameSetupActivity.start(context, WalletTypeSelectActivity.MODE_CREATE_NEW,
                                    chainId);
                        }
                        //WalletTypeSelectActivity.start(context,WalletTypeSelectActivity.MODE_CREATE_NEW);
                        commonOtherPopWindow.dismiss();
                    }
                });
        commonOtherPopWindow.addMenuButton(ResStringUtil.getString(R.string.open_planet_asset_etc_wallet_import), R.drawable.import_wallet)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //恢复钱包
                        if (chainId == IPAssetsConstant.CHAIN_ID_EOS) {
                            WalletAvatarAndNameSetupActivity.start(context, WalletTypeSelectActivity.MODE_RESTORE_OLD,
                                    EosNetParamUtil.getEosChainId());
                        } else {
                            WalletAvatarAndNameSetupActivity.start(context, WalletTypeSelectActivity.MODE_RESTORE_OLD,
                                    chainId);
                        }

                        // WalletTypeSelectActivity.start(context,WalletTypeSelectActivity.MODE_RESTORE_OLD);
                        commonOtherPopWindow.dismiss();
                    }
                });


        if (chainId != 0) {
           /* IPAssetsConstant.ChainEnum blockChainEnum = IPAssetsConstant.ChainEnum.ETH;
            if (chainId == IPAssetsConstant.CHAIN_ID_BTC) {
                blockChainEnum = IPAssetsConstant.ChainEnum.BTC;
            } else if (chainId == IPAssetsConstant.CHAIN_ID_EOS) {
                blockChainEnum = EosNetParamUtil.getEosChainEnum();
            }else if (chainId == IPAssetsConstant.CHAIN_ID_ACT) {
                blockChainEnum = IPAssetsConstant.ChainEnum.ACHAIN;
            } else if (chainId == IPAssetsConstant.CHAIN_ID_BCH) {
                blockChainEnum = IPAssetsConstant.ChainEnum.BCH;
            } else if (chainId == IPAssetsConstant.CHAIN_ID_ETE) {
                blockChainEnum = IPAssetsConstant.ChainEnum.ETE;
            }*/
           String type = ChainParamsUtil.getAssetUnitByChainId(chainId);
            List<Account> list = new AccountDao(context).getAllChildAccount(type);
            String menuTitle = ResStringUtil.getString(R.string.open_planet_asset_etc_wallet_switch)+"（" + list.size() + ")";
            commonOtherPopWindow.addMenuButton(menuTitle, R.drawable.change_wallet)
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //切换钱包
                          /*  if (chainId == IPAssetsConstant.CHAIN_ID_ETH) {
                                Intent intent = new Intent(context, WalletChangeActivity.class);
                                intent.putExtra("wallet_type", IPAssetsConstant.CHAIN_ID_ETH);
                                context.startActivity(intent);
                            } else if (chainId == IPAssetsConstant.CHAIN_ID_BTC) {
                                Intent intent = new Intent(context, WalletChangeActivity.class);
                                intent.putExtra("wallet_type", IPAssetsConstant.CHAIN_ID_BTC);
                                context.startActivity(intent);
                            } else if (chainId == IPAssetsConstant.CHAIN_ID_EOS) {
                                Intent intent = new Intent(context, WalletChangeActivity.class);
                                intent.putExtra("wallet_type", EosNetParamUtil.getEosChainId());
                                context.startActivity(intent);
                            }else if (chainId == IPAssetsConstant.CHAIN_ID_ACT) {
                                Intent intent = new Intent(context, WalletChangeActivity.class);
                                intent.putExtra("wallet_type", IPAssetsConstant.CHAIN_ID_ACT);
                                context.startActivity(intent);
                            } else if (chainId == IPAssetsConstant.CHAIN_ID_BCH) {
                                Intent intent = new Intent(context, WalletChangeActivity.class);
                                intent.putExtra("wallet_type", IPAssetsConstant.CHAIN_ID_BCH);
                                context.startActivity(intent);
                            }else if (chainId == IPAssetsConstant.CHAIN_ID_ETE) {
                                Intent intent = new Intent(context, WalletChangeActivity.class);
                                intent.putExtra("wallet_type", IPAssetsConstant.CHAIN_ID_ETE);
                                context.startActivity(intent);
                            }*/
                            Intent intent = new Intent(context, WalletChangeActivity.class);
                            intent.putExtra("wallet_type", chainId);
                            context.startActivity(intent);
                            commonOtherPopWindow.dismiss();
                        }
                    });
        }
        commonOtherPopWindow.showPopupWindow(imageView);
    }
}
